package com.docker.core.interceptor;

import com.docker.core.constant.ConfigConstant;
import com.docker.core.mvc.Remark;
import com.docker.upload.UploadController;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import kit.docker.interceptor.InterceptorKit;

/**
 * @Author ldl
 * @Create 2020/10/21 021 12:03
 */
@Remark("无token拦截")
public class InterceptorUnToken implements Interceptor {

    @Override
    public void intercept(Invocation inv) {
        if (PropKit.getBoolean(ConfigConstant.API_SECURE, true)) {
            Controller c = inv.getController();

            if (c instanceof UploadController) {
                c.getFiles();
            }

            String appId = c.getPara("app_id");
            String timestamp = c.getPara("timestamp");
            String sign = c.getPara("sign");
            String appVersion = c.getPara("app_version");

            //校验参数完整性
            InterceptorKit.checkField(appId, timestamp, sign, appVersion);
            //公共安全性校验
            InterceptorKit.checkPublic(c.getRequest(), appId, timestamp, sign, null, false);
        }
        inv.invoke();
    }

}
